package com.dd.cloud.user.controller;

import com.dd.cloud.user.service.sms.ISmsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotBlank;

/**
 * 短信控制器
 *
 * @author zk
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/sms")
public class SmsController {
    @Autowired
    private ISmsService iSmsService;

    /**
     * 发送短信验证码
     *
     * @param phone 手机号码
     * @param flag  标识
     * @return 无
     */
    @PostMapping("/code")
    public ResponseEntity<Void> sendCode(@RequestParam(value = "phone", required = false) @NotBlank(message = "手机号不能为空") String phone,
                                         @RequestParam(value = "flag", required = false) Integer flag,
                                         String key,
                                         String code,
                                         HttpServletRequest request,
                                         Integer type) {
        iSmsService.sendCode(phone, flag, request, key, code, type);
        return ResponseEntity.ok().build();
    }

    /**
     * 验证短信验证码
     *
     * @param phone 手机号码
     * @param flag  标识
     * @return 无
     */
    @PostMapping("/verify/code")
    public ResponseEntity<Void> verifyCode(@RequestParam(value = "phone", required = false) @NotBlank(message = "手机号不能为空") String phone,
                                           @RequestParam(value = "code", required = false) @NotBlank(message = "验证码不能为空") String code, @RequestParam(value = "flag", required = false) Integer flag) {
        iSmsService.verifyCode(phone, code, flag);
        return ResponseEntity.ok().build();
    }

    /**
     * 手动发送处方订单发货短信给医生
     *
     * @param tencode
     * @param docId
     * @param pName
     * @param expressNo
     * @param expressName
     */
    @PostMapping("/manual/deliver/pres")
    public ResponseEntity<Void> sendDeliveryPres(String tencode, Integer docId, String pName, String expressNo, String expressName) {
        iSmsService.sendDeliveryPres(tencode, docId, pName, expressNo, expressName);
        return ResponseEntity.ok().build();
    }
}